The present disclosure relates generally to programming languages and compilers in a data processing system and more specifically to program stack management in the data processing system.
Typical computer hardware architectures provide an instruction set comprising instructions with a displacement field for accessing memory locations. For example, an instruction having a base plus displacement format, referred to as base plus offset. In this format a load register instruction has an effective address equal to the displacement value plus the contents of a specified base register.
In another example, an instruction may be of a form of base plus index plus displacement, which is referred to as base plus index plus offset. In this format the load register instruction has an effective address equal to the displacement value plus the contents of a specified base register and the contents of a specified index register.
In a further example as computer hardware architecture evolves, the architecture expands to support multiple sets of instructions used to access memory comprising a short displacement format and a long displacement format. In the short displacement format, the instruction is defined as a traditional 12-bit (short) displacement instruction. Using this type of instruction enables a maximum addressing of +4,095 bytes from the origin (base address). In contrast the long displacement format, defines as an extended 20-bit signed (long) displacement instruction. Using this type of instruction enables a maximum addressing between −524,288 bytes and +524,287 (512K) bytes from the origin (base address). This type of instruction has 8 additional bits appended to the left of the 12-bit displacement (as in the short displacement instruction).
A 20-bit signed displacement enables relative addressing of up to 524,287 bytes beyond the location that is designated by a base register or base-and-index-register pair and up to 524,288 bytes prior to that location. Examples of instruction pairs supporting both short and long displacement as supported in one commercially available example system (z/OS® is a 64-bit operating system for System z® computers, produced by IBM® IBM, z/OS, System z are registered trademarks of IBM Corporation in the United States, other countries, or both) include operation codes of L/LY, LA/LAY, ST/STY, (and other pairs of this type). Examples of additional instructions, which only support a short displacement type, include operation codes of MVC, CLC, and other instructions of this type.
In a typical compiler implementation when instructions are generated the displacement is not known at compilation time and the compiler has to make assumptions about the displacement field. The displacement is known after a stack mapping stage, which occurs after instructions are generated. Therefore when short displacement-only instructions are generated a compiler cannot determine whether corresponding offsets will fit into the short displacement field.
When the offset does not fit into the short displacement, a fix-up to re-create the offset in a separate register is required. The separate register is added to the original displacement and later used as a base register for the particular instruction. Pessimistic assumptions by the compiler for the displacement field result in unnecessary up-front fix-ups whereas optimistic assumptions result in expensive fix-ups for the data that does not fit in the displacement field.
Typical attempts to mitigate the displacement size problem typically use an early stack mapping stage. The early stack mapping stage is performed before instructions are generated providing an estimate of the respective displacements. However a disadvantage of this approach arises when displacements are not accurately computed (for example, extra temps for register spilling can introduce distortions). As well this technique does not consider how the data is used and may inadvertently penalize instructions in a hot areas of the code for the benefit of the infrequently executed sections of the code (cold areas of code).